package com.cqndt.disaster.device.service.impl;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import java.math.BigDecimal;
import javax.annotation.Resource;
import com.cqndt.disaster.device.dao.*;
import com.cqndt.disaster.device.vo.SearchVo;
import com.cqndt.disaster.device.vo.TabSensorVo;

import org.springframework.stereotype.Service;
import com.cqndt.disaster.device.domain.TabDevice;
import com.cqndt.disaster.device.vo.DeviceScaleVo;
import com.cqndt.disaster.device.vo.MonitorScaleVo;
import com.cqndt.disaster.device.vo.DeviceMonitorVo;
import com.cqndt.disaster.device.vo.DeviceInProjectVo;
import com.cqndt.disaster.device.domain.TabDeviceType;
import com.cqndt.disaster.device.domain.TabWarnSetting;
import com.cqndt.disaster.device.service.AnalysisService;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lgb
 * @date 2020-8-28
 * @说明   数据分析
 **/
@Service
public class AnalysisInfluxServiceImpl implements AnalysisService {

	@Resource
	private TbsMapper tbsMapper;
    @Resource
    private TabDeviceMapper tabDeviceMapper;
    @Resource
    private TabDeviceTypeMapper tabDeviceTypeMapper;
    @Resource
    private TabSensorMapper tabSensorMapper;
    @Resource
    private TabSensorInitMapper tabSensorInitMapper;
    @Resource
    private TabDeviceInitialValueMapper tabDeviceInitialValueMapper;
    @Resource
    private TabWarnSettingMapper tabWarnSettingMapper;
    
    @Override
    @Transactional(readOnly=true)
    public Map<String,Object> selecteChart(SearchVo vo) {
        Map<String,Object> map = new HashMap<>();
        Integer type = Integer.valueOf(vo.getSensorType());
        String deviceNo = tabSensorMapper.selectDeviceNoBySensorNo(vo.getSensorNo());
        TabDevice tabDevice = getTabDevice(deviceNo);
        String monitorNo = tabSensorMapper.selectMonitorNoBySensorNo(vo.getSensorNo());
        List<TabDeviceType> tabDeviceType = getDeviceTypeList(monitorNo);
        List<Map<String,Object>> data = new ArrayList<>();
        switch (type) {
	        case 1://裂缝
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsLf(vo);//"x加速度","y加速度","z加速度"
	        	getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"x加速度","y加速度","z加速度");
	        	break;
	        case 2:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsLfjdu(vo);//"x角度","y角度","z角度"
	        	getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"x角度","y角度","z角度");
	        	break;
	        case 3:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsLflx(vo);//"拉线值"
	        	getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"拉线值");
	        	break;
	        case 4:
	        	vo.setSensorNo(monitorNo);
	        	data = tbsMapper.tbsDbwy(vo);
	        	getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"北向偏移","东向偏移","高向偏移");
	        	break;
	        case 11:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDxs(vo);
	        	getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"水位高度");
	        	break;
	        case 50:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDmqxjcy(vo);
	            getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"主向位移(mm)","侧向位移(mm)","沉降位移(mm)");
	            break;
	        case 51:
	        	data = tbsMapper.tbsDlfQlf(vo);
	            getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"x倾角(°)","y倾角(°)","z倾角(°)","拉线(mm)","相对位移量(mm)");
	            break;
	        case 52:
	        	vo.setSensorNo(deviceNo);
            	data = tbsMapper.tbsDbwy61(vo);
            	getParamExplain(vo.getSensorNo(),data,map,tabDevice,"空气温度");
            	break;
	        case 53:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDbwy62(vo);
            	getParamExplain(vo.getSensorNo(),data,map,tabDevice,"空气湿度");
	        	break;
	        case 54:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDbwy63(vo);
            	getParamExplain(vo.getSensorNo(),data,map,tabDevice,"大气压力");
	        	break;
	        case 55:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDbwy64(vo);
            	getParamExplain(vo.getSensorNo(),data,map,tabDevice,"风速");
	        	break;
	        case 56:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDbwy65(vo);
            	getParamExplain(vo.getSensorNo(),data,map,tabDevice,"风向");
	        	break;
	        case 57:
	        	vo.setSensorNo(deviceNo);
	        	data = tbsMapper.tbsDbwy66(vo);
            	getParamExplain(vo.getSensorNo(),data,map,tabDevice,"雨量");
	        	break;
	        case 60:
	        	vo.setSensorNo(deviceNo);
	        	List<Map<String,Object>> datay_60 = new ArrayList<>();
	        	List<Map<String,Object>> data0=tbsMapper.tbsSbwyTimeList1(vo); 
	        	if(!data0.isEmpty()) {
	        		if(deviceNo.equals("sd20200904001")) {
		        		Integer e[]={-2,-4,-6,-8,-10,-12,-14,-16,-18,-20,-22,-24};
		        		map.put("elevation", e);
		        	}else if(deviceNo.equals("sd20200904002")) {
		        		Integer e[]={-2,-4,-6,-8,-10,-12,-14,-16,-18,-20,-22,-24,-26,-28,-30};
		        		map.put("elevation", e);
		        	}else if(deviceNo.equals("sd20200907003")||deviceNo.equals("sd20200907004")) {
		        		Integer e[]={-2,-4,-6,-8,-10,-12,-14,-16,-18,-20,-22,-24,-26,-28,-30,-32,-34,-36,-38,-40};
		        		map.put("elevation", e);
		        	}else if(deviceNo.equals("sd20200909005")||deviceNo.equals("sd20200909006")) {
		        		Integer e[]={-3,-6,-9,-12,-15,-18,-21,-24,-27,-30,-33,-36,-39,-42,-45,-48,-51,-54,-57,-60};
		        		map.put("elevation", e);
		        	}else {
		        		Integer e[]={-3,-6,-9,-12,-15,-18,-21,-24,-27,-30,-33,-36,-39,-42,-45,-48,-51,-54,-57,
		        				-60,-63,-66,-69,-71};
		        		map.put("elevation", e);
		        	}
		        	Integer elevation[] = (Integer[])map.get("elevation");
	        		for(int i=0;i<data0.size();i++) {
	        			Map<String,Object> mapx=new HashMap<String,Object>();
	        			String times = data0.get(i).get("time").toString();
	        			mapx.put("name",times);
	        			String[] values = data0.get(i).get("param1").toString().split(",");
	        			List<String[]> mk1 = new ArrayList<>();
	        			List<String> value3 = new ArrayList<>();
	        			for(int ii=0;ii<values.length;ii++) {
	        				String[] mk = new String[2];
	        				mk[0]=values[(values.length-ii-1)];
	        				mk[1]=elevation[ii].toString();
	        				mk1.add(mk);
	        				String str1="";
	        				if(ii==0 || ii==(values.length-1)) {
	        					str1=values[ii];
	        				}else {
	        					BigDecimal b1 = new BigDecimal(values[ii]);
	        					BigDecimal b2 = new BigDecimal(values[ii-1]);
	        					str1=b1.subtract(b2).doubleValue()+"";
	        				}
	        				value3.add(str1);
	        			}
	        			/** 查询y的偏移量 */
	        			List<Map<String,Object>> data1=tbsMapper.tbsSbwyTimeList2(deviceNo,times); 
	        			if(!data1.isEmpty()) {
	        				String[] values1 = data1.get(0).get("param1").toString().split(",");
		        			List<String[]> mk2 = new ArrayList<>();
		        			List<String> value4 = new ArrayList<>();
		        			for(int ii=0;ii<values1.length;ii++) {
		        				String[] mk = new String[2];
		        				mk[0]=values1[(values1.length-ii-1)];
		        				mk[1]=elevation[ii].toString();
		        				mk2.add(mk);
		        				String str1="";
		        				if(ii==0 || ii==(values1.length-1)) {
		        					str1=values[ii];
		        				}else {
		        					BigDecimal b1 = new BigDecimal(values1[ii]);
		        					BigDecimal b2 = new BigDecimal(values1[ii-1]);
		        					str1=b1.subtract(b2).doubleValue()+"";
		        				}
		        				value4.add(str1);
		        			}
		        			mapx.put("mk2",mk2);
		        			mapx.put("value1",values1);
		        			mapx.put("value4",value4);
	        			}
	        			mapx.put("mk1",mk1);
	        			mapx.put("value",values);
	        			mapx.put("value2",map.get("elevation"));
	        			mapx.put("value3",value3);
	        			datay_60.add(mapx);
	        		}
	        	}
	        	map.put("value",datay_60);
	        	break;
	        case 61:
	        	List<Map<String,Object>> datay_61 = new ArrayList<>();
	        	map.put("value",datay_61);
	        	break;
             default: throw new RuntimeException("无该"+type+"类型设备!");
        }
        return map;
    }

    @Override
    @Transactional(readOnly=true)
    public Map<String,Object> selecteChart2(SearchVo vo) {
        Map<String,Object> map = new HashMap<>();
        Integer type = Integer.valueOf(vo.getSensorType());
        String deviceNo = tabSensorMapper.selectDeviceNoBySensorNo(vo.getSensorNo());
        TabDevice tabDevice = getTabDevice(deviceNo);
        String monitorNo = tabSensorMapper.selectMonitorNoBySensorNo(vo.getSensorNo());
        List<TabDeviceType> tabDeviceType = getDeviceTypeList(monitorNo);
        List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
        switch (type) {
            case 1://裂缝
            	vo.setSensorNo(deviceNo);
            	data = tbsMapper.tbsLf(vo);//"x加速度","y加速度","z加速度","拉线值"
            	getParamExplain2(vo.getSensorNo(),type,data,map,tabDevice,tabDeviceType,"x加速度","y加速度","z加速度","x角度","y角度","z角度","拉线值");
            	break;
            case 4:
	        	vo.setSensorNo(monitorNo);
	        	data = tbsMapper.tbsDbwy(vo);
	        	getParamExplain2(vo.getSensorNo(),type,data,map,tabDevice,tabDeviceType,"北向变形","东向变形","高向变形");
	        	break;
            case 50:
                //地面倾斜
            	data = tbsMapper.tbsDmqxjcy(vo);
                getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"主向位移(mm)","侧向位移(mm)","沉降位移(mm)");
                if (map != null && map.size() != 0) {
                    niHeQuXian(vo.getSensorNo(),map,"主向位移(mm)","侧向位移(mm)","沉降位移(mm)");
                }
                break;
            case 51:
                //地裂缝、墙裂缝
            	data = tbsMapper.tbsDlfQlf(vo);
                getParamExplain(vo.getSensorNo(),data,map,tabDevice,tabDeviceType,"x倾角(°)","y倾角(°)","z倾角(°)","拉线(mm)","相对位移量(mm)");
                if (map != null && map.size() != 0) {
                    niHeQuXian(vo.getSensorNo(),map,"x倾角(°)","y倾角(°)","z倾角(°)","拉线(mm)","相对位移量(mm)");
                }
                break;
            case 52://6要素数据
            	data = tbsMapper.tbsDbwy66(vo);
            	getParamExplain2(vo.getSensorNo(),type,data,map,tabDevice,tabDeviceType,"空气温度","空气湿度","大气压力","风速","风向","雨量");
            	break;
            default: throw new RuntimeException("无该"+type+"类型设备!");
        }
        return map;
    }

    /**
     * @param sensorNo
     * @param map
     * @param name 
     * @return 构造拟合曲线需要的菜单
     */
    private void niHeQuXian(String sensorNo, Map<String, Object> map, String... name) {
        //拟合曲线需要的菜单
        List<Map<String,Object>> deviceTypeName = tabDeviceTypeMapper.getDeviceTypeNameBySensorNo(sensorNo);
        for (Map<String,Object> map11 : deviceTypeName) {
            String type1 = map11.get("deviceType").toString();
            List<Map<String, Object>> monitorName = tabDeviceTypeMapper.getMonitorNameBySensorNo(sensorNo, type1);
            for (Map<String, Object> mn : monitorName) {
                List<Map<String, Object>> ch = new ArrayList<>();
                for (String s : name) {
                    Map<String, Object> childrenMap = new HashMap<>();
                    childrenMap.put("deviceNo", mn.get("deviceNo"));
                    childrenMap.put("deviceTypeName", s);
                    childrenMap.put("deviceType", s);
                    ch.add(childrenMap);
                }
                mn.put("children", ch);
            }
            map11.put("children", monitorName);
        }
        map.put("niHeQuXian", deviceTypeName);
    }

    /**
     * @param results
     * @param map
     * @param name
     * @return 转换对应的结果集
     **/
    private void getParamExplain(String sensorNo,List<Map<String,Object>> results,
    		Map<String,Object> map,TabDevice tabDevice,List<TabDeviceType> tabDeviceType,String... name) {
        if (results.size() <= 0) {
            return;
        }
        BigDecimal maxData = null;
        BigDecimal minData = null;
        for (int i = 0; i < name.length; i++) {
            List<Map<String, Object>> mapList = new ArrayList<>();
            Map<String,Object> initValueMap = tabSensorInitMapper.getDataByFiledName(sensorNo,name[i]);
            for (Map<String, Object> mapResult : results) {
                Object time =mapResult.get("time").toString();
                if (mapResult.get("param" + (i + 1)) != null && mapResult.get("param" + (i + 1)) != "") {
                    BigDecimal initValue = BigDecimal.ZERO;
                    if (null != initValueMap && null != initValueMap.get("init_value")) {
                        initValue = new BigDecimal(initValueMap.get("init_value").toString());
                    }
                    BigDecimal value = new BigDecimal(mapResult.get("param" + (i + 1)).toString()).subtract(initValue);
                    maxData = maxData == null ? value : maxData.max(value);
                    minData = minData == null ? value : minData.min(value);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("name", time);
                    List<Object> list1 = new ArrayList<>();
                    list1.add(time);
                    list1.add(value);
                    map1.put("value", list1);
                    mapList.add(map1);
                }
            }
            if (mapList.size() > 0) {
                map.put("maxData", maxData);
                map.put("minData", minData);
                map.put(name[i], mapList);
                List<Map<String, Object>> list1 = new ArrayList<>();
                for (TabDeviceType tabDeviceType1 : tabDeviceType) {
                    if (tabDeviceType1 != null) {
                        Map<String, Object> map1 = new HashMap<>();
                        BigDecimal divide = maxData.abs().add(minData.abs());
                        BigDecimal divide1= divide.divide(new BigDecimal("5"),1,BigDecimal.ROUND_HALF_UP);
                        map1.put("scale",tabDeviceType1.getScale()==null ? divide1:tabDeviceType1.getScale());
                        map1.put("type", tabDeviceType1.getType() ==null ? 0: tabDeviceType1.getType());
                        list1.add(map1);
                    }
                }
                map.put("scale", list1);
            }
        }
    }

    private void getParamExplain2(String sensorNo,Integer type,List<Map<String, Object>> results,
    	Map<String,Object> map,TabDevice tabDevice,List<TabDeviceType> tabDeviceType,String... name) {
        if (results.size() <= 0) {
            return;
        }
        BigDecimal maxData = null;
        BigDecimal minData = null;
        for (int i = 0; i < name.length; i++) {
            List<Object> result = new ArrayList<>();
            List<Map<String, Object>> mapList = new ArrayList<>();
            Map<String,Object> initValueMap = tabSensorInitMapper.getDataByFiledName(sensorNo,name[i]);
            for (Map<String, Object> mapResult : results) {
                Object time = mapResult.get("time");
                if (mapResult.get("param" + (i + 1)) != null && mapResult.get("param" + (i + 1)) != "") {
                    BigDecimal initValue = BigDecimal.ZERO;
                    if (null != initValueMap && null != initValueMap.get("init_value")) {
                        initValue = new BigDecimal(initValueMap.get("init_value").toString());
                    }
                    if ("5".equals(tabDevice.getDeviceType())) {
                        List<Object> list1 = new ArrayList<>();
                        for (int p = 0; p < 10; p++) {
                            BigDecimal value = new BigDecimal(mapResult.get("param" + (p + 1)).toString()).subtract(initValue);
                            list1.add(value);
                        }
                        Map<String, Object> map1 = new HashMap<>();
                        map1.put("name", time);
                        map1.put("value", list1);
                        mapList.add(map1);
                    } else {
                        BigDecimal value = new BigDecimal(mapResult.get("param" + (i + 1)).toString()).subtract(initValue);
                        maxData = maxData == null ? value : maxData.max(value);
                        minData = minData == null ? value : minData.min(value);
                        Map<String, Object> map1 = new HashMap<>();
                        map1.put("name", time);
                        List<Object> list1 = new ArrayList<>();
                        list1.add(time);
                        list1.add(value);
                        map1.put("value", list1);
                        mapList.add(map1);
                    }
                }
            }
            List<Integer[]> list1 = new ArrayList<>();
            Integer[] array1;
            Integer[] array2;
            Integer[] array3;
            Integer[] array4;
            Integer[] array5;
            Integer[] array6;
            switch (type) {
            	case 10://雨量
	                array1 = new Integer[]{null, -50};
	                array2 = new Integer[]{-5, -40};
	                array3 = new Integer[]{-5, 0};
	                array4 = new Integer[]{0, 40};
	                array5 = new Integer[]{40, 50};
	                array6 = new Integer[]{50, null};
	                list1.add(array1);
	                list1.add(array2);
	                list1.add(array3);
	                list1.add(array4);
	                list1.add(array5);
	                list1.add(array6);
	                break;
            	case 22://拉线是位移
	                array1 = new Integer[]{null, -50};
	                array2 = new Integer[]{-50, -40};
	                array3 = new Integer[]{-40, 0};
	                array4 = new Integer[]{0, 40};
	                array5 = new Integer[]{40, 50};
	                array6 = new Integer[]{50, null};
	                list1.add(array1);
	                list1.add(array2);
	                list1.add(array3);
	                list1.add(array4);
	                list1.add(array5);
	                list1.add(array6);
	                break;
                case 32://gnss
                    array1 = new Integer[]{null, -50};
                    array2 = new Integer[]{-50, -40};
                    array3 = new Integer[]{-40, 0};
                    array4 = new Integer[]{0, 40};
                    array5 = new Integer[]{40, 50};
                    array6 = new Integer[]{50, null};
                    list1.add(array1);
                    list1.add(array2);
                    list1.add(array3);
                    list1.add(array4);
                    list1.add(array5);
                    list1.add(array6);
                    break;
                default :
                	array1 = new Integer[]{null, -50};
                    array2 = new Integer[]{-50, -40};
                    array3 = new Integer[]{-40, 0};
                    array4 = new Integer[]{0, 40};
                    array5 = new Integer[]{40, 50};
                    array6 = new Integer[]{50, null};
                    list1.add(array1);
                    list1.add(array2);
                    list1.add(array3);
                    list1.add(array4);
                    list1.add(array5);
                    list1.add(array6);
                    break;
            }
            result.add(list1);
            result.add(mapList);
            if (mapList.size() > 0) {
                map.put("maxData", maxData);
                map.put("minData", minData);
                map.put(name[i], result);
                List<Map<String, Object>> list2 = new ArrayList<>();
                for (TabDeviceType tabDeviceType1 : tabDeviceType) {
                    if (tabDeviceType1 != null) {
                        Map<String, Object> map1 = new HashMap<>();
                        map1.put("scale", tabDeviceType1.getScale() == null ? 0 : tabDeviceType1.getScale());
                        map1.put("type", tabDeviceType1.getType() == null ? 0 : tabDeviceType1.getType());
                        list2.add(map1);
                    }
                }
                map.put("scale", list2);
            }
        }
    }
    
    @Override
    @Transactional(readOnly=true)
    public List<DeviceInProjectVo> selectDeviceByProjectId(String projectId) {
        List<DeviceInProjectVo> list = tabDeviceMapper.selectByProjectId(projectId);
        if (list.size() > 0) {
            for (DeviceInProjectVo vo : list) {
                List<DeviceMonitorVo> listNo = tabDeviceMapper.selectByPIdAndDtype(projectId, vo.getDeviceType());
                vo.setListNo(listNo);
            }
        }
        return list;
    }
    private TabDevice getTabDevice(String deviceNo) {
        TabDevice tabDevice = tabDeviceMapper.getDevice(deviceNo);
        return tabDevice;
    }
    private List<TabDeviceType> getDeviceTypeList(String monitorNo){
    	List<TabDeviceType> typeList = tabDeviceMapper.getDeviceType(monitorNo);
    	return typeList;
    }
	@Override
	@Transactional(readOnly=true)
	public TabWarnSetting getSettingBySensorNo(String sensorNo) {
		return tabWarnSettingMapper.getSettingBySensorNo(sensorNo);
	}

	@Override
	@Transactional(readOnly=true)
	public List<DeviceScaleVo> getSensorType(String projectId) {
		List<DeviceScaleVo> scaleVoList = new ArrayList<>();
		List<DeviceInProjectVo> list = tabDeviceMapper.selectByProjectId(projectId);
        if (list.size() > 0) {
            for (DeviceInProjectVo vo : list) {
            	DeviceScaleVo dsvo = new DeviceScaleVo();
            	dsvo.setDeviceType(vo.getDeviceType());
            	dsvo.setDeviceTypeName(vo.getDeviceTypeName());
            	List<MonitorScaleVo> mvo = tabDeviceMapper.selectMointorScaleVoList(projectId,vo.getDeviceType());
                if(!mvo.isEmpty()) {
                	for(MonitorScaleVo msvo : mvo) {
                		List<Object> data = new ArrayList<>();
            			List<TabDeviceType> typeList=tabDeviceTypeMapper.selectDeviceType(msvo.getMonitorNo());
            			for(TabDeviceType deviceType : typeList) {
            				Map<String,Object> map = new HashMap<String,Object>();
            				map.put("deviceType",deviceType.getId());
                    		map.put("deviceTypeName",deviceType.getType());
                    		data.add(map);
            			}
                    	msvo.setChildren(data);
                	}
                }
            	dsvo.setChildren(mvo);
            	scaleVoList.add(dsvo);
            }
        }
        return scaleVoList;
	}
    
	
	
	
	
	
	
	/**
     * @param results
     * @param map
     * @param name
     * @return 转换对应的结果集
     **/
    private void getParamExplain(String sensorNo,List<Map<String,Object>> results,
    		Map<String,Object> map,TabDevice tabDevice,String... name) {
        if (results.size() <= 0) {
            return;
        }
        BigDecimal maxData = null;
        BigDecimal minData = null;
        for (int i = 0; i < name.length; i++) {
            List<Map<String, Object>> mapList = new ArrayList<>();
            Map<String,Object> initValueMap = tabSensorInitMapper.getDataByFiledName(sensorNo,name[i]);
            for (Map<String, Object> mapResult : results) {
                Object time =mapResult.get("time").toString();
                if (mapResult.get("param" + (i + 1)) != null && mapResult.get("param" + (i + 1)) != "") {
                    BigDecimal initValue = BigDecimal.ZERO;
                    if (null != initValueMap && null != initValueMap.get("init_value")) {
                        initValue = new BigDecimal(initValueMap.get("init_value").toString());
                    }
                    BigDecimal value = new BigDecimal(mapResult.get("param" + (i + 1)).toString()).subtract(initValue);
                    maxData = maxData == null ? value : maxData.max(value);
                    minData = minData == null ? value : minData.min(value);
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("name", time);
                    List<Object> list1 = new ArrayList<>();
                    list1.add(time);
                    list1.add(value);
                    map1.put("value", list1);
                    mapList.add(map1);
                }
            }
            if (mapList.size() > 0) {
                map.put("maxData", maxData);
                map.put("minData", minData);
                map.put(name[i],mapList);
                List<Map<String,Object>> list1 = new ArrayList<>();
                List<TabSensorVo.Scale> scaleList = tabSensorMapper.findSensorScale(sensorNo,name[i]);
                for (TabSensorVo.Scale scaleVo : scaleList) {
                    if (scaleVo != null) {
                        Map<String,Object> map1 = new HashMap<>();
                        BigDecimal divide = maxData.abs().add(minData.abs());
                        BigDecimal divide1= divide.divide(new BigDecimal("5"),1,BigDecimal.ROUND_HALF_UP);
                        map1.put("scale",scaleVo.getScale()==null ? divide1:scaleVo.getScale());
                        map1.put("type", scaleVo.getType() ==null ? 0: scaleVo.getType());
                        list1.add(map1);
                    }
                }
                map.put("scale", list1);
            }
        }
    }
	
}